L.TeacherMonitor = L.Class.extend({
	includes: L.Mixin.Events,

	initialize: function(couplingOptions) {
		this._teacherRoomId = null;
		this._followingEnabled = false;
		this._couplingOptions = couplingOptions;		
		this._couple(this._couplingOptions);
	},
	
	setFollowingEnabled: function(enabled, subjectVersionId, activityId) {
//		console.log('setFollowingEnabled: function(enabled) {');
		Skt.teacherMonitor._followingEnabled = enabled;
		this._followingEnabled = enabled;
		
		console.log(enabled && Skt.tvManager != null);
		if ( enabled && Skt.tvManager != null )
			Skt.tvManager.requestFollowingJoin(subjectVersionId, activityId);
		
		Skt.teacherMonitor.fire('followingEnabledChanged',{
			roomId: Skt.teacherMonitor._teacherRoomId,
			followingEnabled: Skt.teacherMonitor._followingEnabled
		});
	},
	
	isFollowingEnabled: function() {
		return this._followingEnabled;
	},
	
	setTeacherRoomId: function(roomId) {
//		console.log('setTeacherRoomId: function(roomId) {');
//		console.log(roomId);
		Skt.teacherMonitor._teacherRoomId = roomId;
		this._teacherRoomId = roomId;
//		console.log(Skt.teacherMonitor._teacherRoomId);
		Skt.teacherMonitor.fire('teacherRoomChanged', {
			roomId: Skt.teacherMonitor._teacherRoomId,
			followingEnabled: Skt.teacherMonitor._followingEnabled
		});
	},
	
	getTeacherRoomId: function() {
		return this._teacherRoomId;
	},
	
	handleCurrentCanvasChange: function(params) {
//		console.log('handleCurrentCanvasChange: function(params) {');
		this.setTeacherRoomId(params.roomId);
	},
	
	toggleFollowingEnabled: function() {
		this.setFollowingEnabled(!this._followingEnabled);
//		Skt.teacherMonitor.setFollowingEnabled(!Skt.teacherMonitor._followingEnabled);
	},
	
	_couple: function(couplingOptions) {
		if ( couplingOptions && couplingOptions.enabled ) {
			couplingOptions.adapter.coupleObject(
				couplingOptions.carriedId, 
				this,
				{
					messageType: "EVENT",
					explicitMapping: ["setTeacherRoomId", "setFollowingEnabled"]
				}
			);
		}
	}
	
});